<?php
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../DAO/TbluserDAO.php';
class AuthenticationService
{
	public function login (BaseContext $context, ServiceResult $result, $username, $password)
	{
		try 
		{			
			$userDao = new TbluserDAO($context);	
			$password = Tool::md5_base64($password);					
			$userDomain = $userDao->findByUnamePass($username, $password);			
			if($userDomain != null)
			{
				return $userDomain;
			}
			$result->setSuccess();
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
		}
		return false;
	}
	
	public function update (BaseContext $context, ServiceResult $result, $tbluserDomain)
	{
		try 
		{			
			$userDao = new TbluserDAO($context);
			$userDao->update($tbluserDomain);
			$result->setSuccess();
			return true;
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
		}
		return false;
	}
	
	public function getLockOutTimeByUserName(BaseContext $context, ServiceResult $result,$name)
	{
		$lockOutTime = 0;
		try 
		{			
			$userDao = new TbluserDAO($context);
			$lockOutTime = $userDao->getLockOutTimeByName($name);
			$result->setSuccess();
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
		}
		return $lockOutTime;
	}
	
	public function updateLockOutTimeByName(BaseContext $context, ServiceResult $result,$name, $lockOutTime)
	{
		try 
		{			
			$userDao = new TbluserDAO($context);
			$lockOutTime = $userDao->updateLockOutTimeByName($name,$lockOutTime);
			$result->setSuccess();
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
		}
	}
	
}
?>